package com.example.demo.controller;

import com.example.demo.controller.vo.ResponseResult;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin")
public class IndexController {

    @GetMapping("/statistics1")
    public ResponseResult<?> getStatistics1(@RequestHeader("token") String token) {
        log.info("Getting statistics1 data");
        return ResponseResult.success(new Object() {
            @SuppressWarnings("unused")
            public final Object data = new Object() {
                public final Object[] panels = new Object[] {
                    new Object() {
                        public final String title = "支付订单";
                        public final int value = 51;
                        public final String unit = "年";
                        public final String unitColor = "success";
                        public final String subTitle = "总支付订单";
                        public final int subValue = 51;
                        public final String subUnit = "";
                    },
                    new Object() {
                        public final String title = "订单量";
                        public final int value = 555;
                        public final String unit = "周";
                        public final String unitColor = "danger";
                        public final String subTitle = "转化率";
                        public final String subValue = "60%";
                        public final String subUnit = "";
                    },
                    new Object() {
                        public final String title = "销售额";
                        public final double value = 3.74;
                        public final String unit = "年";
                        public final String unitColor = "";
                        public final String subTitle = "总销售额";
                        public final double subValue = 3.74;
                        public final String subUnit = "";
                    },
                    new Object() {
                        public final String title = "新增用户";
                        public final int value = 22;
                        public final String unit = "年";
                        public final String unitColor = "warning";
                        public final String subTitle = "总用户";
                        public final int subValue = 22;
                        public final String subUnit = "人";
                    }
                };
            };
        });
    }

    @GetMapping("/statistics2")
    public ResponseResult<?> getStatistics2(@RequestHeader("token") String token) {
        log.info("Getting statistics2 data");
        return ResponseResult.success(new Object() {
            @SuppressWarnings("unused")
            public final Object data = new Object() {
                public final Object[] goods = new Object[] {
                    new Object() {
                        public final String label = "审核中";
                        public final int value = 2;
                    },
                    new Object() {
                        public final String label = "销售中";
                        public final int value = 122;
                    },
                    new Object() {
                        public final String label = "已下架";
                        public final int value = 62;
                    },
                    new Object() {
                        public final String label = "库存预警";
                        public final int value = 6;
                    }
                };
                public final Object[] order = new Object[] {
                    new Object() {
                        public final String label = "待付款";
                        public final int value = 171;
                    },
                    new Object() {
                        public final String label = "待发货";
                        public final int value = 16;
                    },
                    new Object() {
                        public final String label = "已发货";
                        public final int value = 1;
                    },
                    new Object() {
                        public final String label = "退款中";
                        public final int value = 17;
                    }
                };
            };
        });
    }

    @GetMapping("/statistics3")
    public ResponseResult<?> getStatistics3(@RequestHeader("token") String token,
                                          @RequestParam String type) {
        log.info("Getting statistics3 data, type={}", type);
        @SuppressWarnings("unused")
        final Object data_week = new Object() {
            public final String[] x = new String[] {
                "07-24", "07-23", "07-22", "07-21", "07-20", "07-19", "07-18"
            };
            public final int[] y = new int[] {
                51, 0, 1, 1, 0, 2, 1
            };
        };

        @SuppressWarnings("unused")
        final Object data_hour = new Object() {
            public final String[] x = new String[] {
                "00","23","22","21","20","19","18","17","16","15","14","13","12","11","10","09","08","07","06","05","04","03","02","01"
            };
            public final int[] y = new int[] {
                0,0,0, 0, 0,4,6,3,0,6,3,0,0,11,18,0,0,0,0,0,0,0,0,0
            };
        };

        @SuppressWarnings("unused")
        final Object data_month = new Object() {
            public final String[] x = new String[] {
                "07-24",
                "07-23",
                "07-22",
                "07-21",
                "07-20",
                "07-19",
                "07-18",
                "07-17",
                "07-16",
                "07-15",
                "07-14",
                "07-13",
                "07-12",
                "07-11",
                "07-10",
                "07-09",
                "07-08",
                "07-07",
                "07-06",
                "07-05",
                "07-04",
                "07-03",
                "07-02",
                "07-01",
                "06-30",
                "06-29",
                "06-28",
                "06-27",
                "06-26",
                "06-25"
            };
            public final int[] y = new int[] {
                51,
                0,
                1,
                1,
                0,
                2,
                1,
                0,
                0,
                0,
                2,
                0,
                1,
                0,
                5,
                1,
                0,
                0,
                0,
                1,
                0,
                0,
                4,
                6,
                0,
                0,
                0,
                0,
                0,
                0
            };
        };

        Object re = data_week;
        if(type.equals("month")) {
            re = data_month;
        }
        if(type.equals("hour")) {
            re = data_hour;
        }

        return ResponseResult.success(re);
    }
}
